package com.swiftride.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import com.swiftride.pojo.param.RegisterParam;
import com.swiftride.pojo.vo.LoginVo;
import com.swiftride.result.R;
import com.swiftride.service.ILoginService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;


@Tag(name = "小程序登录表", description = "小程序登录表")
@RestController
@RequestMapping("/app/login")
@Slf4j
public class AppLoginController {

    @Autowired
    public ILoginService loginService;

    @Operation(summary = "小程序注册", description = "小程序注册接口")
    @Parameter(name = "registerSaveLoginParam", description = "保存的对象", required = true)
    @PostMapping
    @SaIgnore
    public R<Long> register(@RequestBody @Valid RegisterParam registerParam) {
        Long loginId = loginService.register(registerParam);
        return R.success(loginId);
    }

    @Operation(summary = "小程序登录", description = "小程序登录")
    @Parameter(name = "openidCode", description = "获取openid的code", required = true)
    @GetMapping("/wxLogin/{openidCode}/{loginType}")
    @SaIgnore
    public R<LoginVo> wxLogin(@PathVariable("openidCode") @NotNull(message = "数据不能为空") String openidCode,
                              @PathVariable("loginType") @NotNull(message = "数据不能为空") Integer loginType) {
        return R.success(loginService.wxLogin(openidCode, loginType));
    }
}
